package com.hippy.erya.config.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j
@Component
public class LogSaveInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        return true;
    }




    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o,
                           ModelAndView modelAndView) throws Exception {
        // 请求日志保存，并清理ThredLocal当前线程的资源
       /* try {
            Map<String, Object> mapContext = ActionContext.getMapContext();
            Map<String,Object> logMap = (Map<String,Object>)mapContext.get("logMap");

            // 起始时间戳，用来计算处理单个请求耗时用
            long startMillis         = (Long)mapContext.get("startMillis");
            // 完成时间戳，用来计算处理单个请求耗时用
            long endMillis           = System.currentTimeMillis();

            logMap.put("useMillis",endMillis - startMillis);

            //publishMsgToPaymentLogMQ(logMap);

        }catch (Exception e1){
            log.error("记录消息失败：",e1);
        }*/

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                                Object o, Exception e) throws Exception {
        // Do nothing because of X and Y.
    }

}
